<template>
  <DataList 
  :cate="cate" 
  :cols="cols"
  :name="name"
  :excelHeader="excelHeader"
  :groupCheck = "groupCheck" 
 ref="datalist"
  skipExcelNumber="3" />
</template>
<script>
import DataList from "@/components/DataList";
import { getUser } from "@/utils/auth";
import {get开设专业} from  "@/api/开设专业"
import { addDgsx, deleteDgsx, updateDgsx, getDgsx, bulkAddDgsx } from "@/api/顶岗实习.js";
import {findComponent} from "@/utils/ui";
import linq from "linq"
export default {
  components: {
    DataList
  },
  data() {
    return {
      cate: "A7-4顶岗实习表",
      name: "7.4 顶岗实习表",
      excelHeader:{B3:"专业所属系部代码",C3:"专业所属系部名称",D3:"专业代码",E3:"专业名称（全称）",F3:"专业方向代码",G3:"专业方向名称（全称）",H3:"毕业生总数（人）",I3:"应届毕业生顶岗实习情况",I4:"顶岗实习毕业生总数（人）",J4:"企业录用顶岗实习毕业生数（人）",K4:"企业录用率（%）",L4:"顶岗实习对口毕业生数（人）",M4:"顶岗实习对口率（%）",N3:"顶岗实习与保险情况",N4:"顶岗实习单位总数（个）",O4:"顶岗实习学生总数（人）",P4:"参加保险学生数（人）",Q4:"保险险种名称(全称)（保险费出资方）",R3:"顶岗实习情况",R4:"主要实习岗位",S4:"主要实习单位",T4:"实习人数（人）",U4:"实习时间（月）"},

      cols: [
        { label: "专业所属系部代码", prop: "BMBH" },
        { label: "专业所属系部名称", prop: "BMMC" },
        { label: "专业代码", prop: "ZYDM" },
        { label: "专业名称(全称)", prop: "ZYMC" },
        { label: "专业方向代码", prop: "ZYFXDM" },
        { label: "专业方向名称(全称)", prop: "ZYFXMC" },
        { label: "毕业生总数(人)", prop: "BYSS" },
        { label: "应届毕业生顶岗实现情况" ,data:[
            {label:"顶岗实习毕业生总数(人)",prop:"DGSXBYSZS"},{ label: "企业录取顶岗实习毕业生总数(人)", prop: "DGSXDKBYSS" },
        { label: "企业录用率(%)", prop: "LYBYSBL" },{ label: "顶岗实习对口毕业生数(人)", prop: "QYLYDGSXBYSS" },
        { label: "顶岗实习对口率(%)", prop: "DGSXDKL" }
        ]},
        { label: "顶岗实习与保险情况" ,data:[
            {label:"顶岗实习单位总数(人)",prop:"BXQK_DGSXDWZS"},{ label: "顶岗实习学生总数(人)", prop: "BXQK_CZBXSSS" },
        { label: "参加保险学生数(人)", prop: "BXQK_CZBXSSS" },{ label: "保险险种名称(全称)(保险费出资方)", prop: "BXQK_BXXZMC" }
        ]},
        { label: "顶岗实习情况" ,data:[
            {label:"主要实习岗位",prop:"DGSX_ZYSXGW"},{ label: "主要实习单位", prop: "DGSX_ZYSXDW" },
        { label: "实习人数(人)", prop: "DGSX_SXRS" },{ label: "实习时间(月)", prop: "DGSX_SXSJ" }
        ]}
      ],
      groupCheck:[{data:["DGSXBYSZS","DGSXDKBYSS","LYBYSBL","QYLYDGSXBYSS","DGSXDKL"],desc:'请完善应届毕业生顶岗实现情况的输入'},
      {data:["BXQK_DGSXDWZS","BXQK_CZBXSSS","BXQK_CZBXSSS","BXQK_BXXZMC"],desc:'请完善顶岗实习与保险情况的输入'},
      {data:["DGSX_ZYSXGW","DGSX_ZYSXDW","DGSX_SXRS","DGSX_SXSJ"],desc:'请完善顶岗实习情况的输入'}]
    };
  },
  methods: {
    getSummaries(list){
      //
        const sums = [];
         this.cols.forEach((column, index) => {
            sums[index]="";
        });
         sums[0]="合计";
         sums[6]="系部数:"+linq.from(list).distinct("$.BMBH").count()
         sums[8]="专业数:"+linq.from(list).distinct("$.ZYDM").count()
         sums[10]="方向数:"+linq.from(list).distinct("$.ZYFXDM").count()
         sums[12]="总人数:"+linq.from(list).sum("$.BYSS")
         sums[13]=""+linq.from(list).sum("$.DGSXBYSZS")
         sums[14]=""+linq.from(list).sum("$.BXQK_DGSXXSZS")
         sums[15]=""+((linq.from(list).sum("$.BXQK_DGSXXSZS")/linq.from(list).sum("$.DGSXBYSZS"))*100).toFixed(2)
         sums[16]=""+linq.from(list).sum("$.QYLYDGSXBYSS")
         sums[17]=""+((linq.from(list).sum("$.QYLYDGSXBYSS")/linq.from(list).sum("$.DGSXBYSZS"))*100).toFixed(2)
         sums[18]=""+linq.from(list).sum("$.BXQK_DGSXDWZS")
         sums[19]=""+linq.from(list).sum("$.BXQK_CZBXSSS")
         sums[20]=""+linq.from(list).sum("$.BXQK_CZBXSSS")
         sums[24]=""+linq.from(list).sum("$.DGSX_SXRS")
         sums[26]= "通过:"+linq.from(list).where("$.审核状态=='通过'").count();
         sums[26]+= ",不通过:"+linq.from(list).where("$.审核状态=='不通过'").count();
         sums[26] += ",待审核:"+linq.from(list).where("$.审核状态=='待审核'").count();
 
       return sums;
      //
    },
      async  onDlgCreated(model) {
           var dd = findComponent(this,"ZYFXMC");
          var ZYFXMC = linq.from( this.$root.开设专业).distinct("$.ZYFXMC").toArray();
        
          dd.$attrs.items = ZYFXMC.map(item => {
            return { label: item.ZYFXMC, value: item.ZYFXMC};
          });
    },
    async  bulkAdd(array){
       await  bulkAddDgsx({Dgsx:array});
    },
     check(array,list) {
     return new Promise(async (resolve,reject)=>{
         try{
          var user = getUser();
          var 专业 = await get开设专业(user.XXID,user.CJPC)
           
          //是否已经存在相同
          
          var err =  linq.from(array).select("$.ZYDM+','+$.ZYFXDM").except(linq.from(专业).select("$.ZYDM+','+$.ZYFXDM").toArray()).toArray();
          linq.from(array).where(e=>err.indexOf(e.ZYDM+','+e.ZYFXDM) !==-1).forEach(e=>e.error=e.error?e.error+";":''+"开设专业表不存在对应的专业代码与专业方向代码组合");
        
            resolve();
          }catch(e){
            reject(e);
          }
     }) 
    },
    calField(list){
      list.forEach(model=>{
         model.LYBYSBL=((Number(model.DGSXDKBYSS)/Number(model.DGSXBYSZS))*100).toFixed(2)+'';
      model.DGSXDKL=((Number(model.QYLYDGSXBYSS)/Number(model.DGSXBYSZS))*100).toFixed(2)+'';
           model.LYBYSBL=isNaN(model.LYBYSBL)?0:model.LYBYSBL;
        model.DGSXDKL=isNaN(model.DGSXDKL)?0:model.DGSXDKL;

      })
     },
    onChange(model, field, value) {
      model.LYBYSBL=((Number(model.DGSXDKBYSS)/Number(model.DGSXBYSZS))*100).toFixed(2)+'';
      model.DGSXDKL=((Number(model.QYLYDGSXBYSS)/Number(model.DGSXBYSZS))*100).toFixed(2)+'';
      //
     if (field == "ZYFXMC") {
        
        var temp =  linq.from( this.$root.开设专业).first(item=>item.ZYFXMC==value);
        model.BMBH = temp.BMBH;
        model.BMMC = temp.BMMC;
        model.ZYMC = temp.ZYMC;
        model.ZYDM = temp.ZYDM;
        
        model.ZYFXDM = temp.ZYFXDM;
        
      }
      //
    },
    
    
    async fetchData() {
      var user =  getUser()
      var datas = await getDgsx(user.XXID,user.CJPC);
      return datas;
    },
    onadd(model) {
      //
      var temp = JSON.parse(JSON.stringify(model))
      return new Promise(async (resolve,reject)=>{
          this.check(reject,temp);
      
          console.log(JSON.stringify(temp));
          var model = await addDgsx(temp);
          resolve(model);
      })
      
    },
    onupdate(model) {
      //
      var temp = JSON.parse(JSON.stringify(model))
      return new Promise(async (resolve,reject)=>{
          this.check(reject,temp);
          console.log(JSON.stringify(temp));
          var model = await updateDgsx(temp);
          resolve(model);
      })
      //
    },
    ondelete(model) {
       var temp = JSON.parse(JSON.stringify(model))
      return new Promise(async (resolve,reject)=>{
         await deleteDgsx(temp);
          resolve();
      })
    }
  }
};
</script>
<style>
</style>